namespace ProxyServer.ProxyImpl
{
    public interface ILogger
    {
        void Error(string message);

        void Warn(string message);

        void Info(string message);

        event LogPresent Logged;
    }

    public enum LogLevel
    {
        Info,
        Warn,
        Error
    }

    public class Log
    {
        private readonly LogLevel level;
        private readonly string message;

        public Log(string message, LogLevel level)
        {
            this.message = message;
            this.level = level;
        }

        public string Message
        {
            get { return message; }
        }

        public LogLevel Level
        {
            get { return level; }
        }
    }

    public delegate void LogPresent(Log log);

    public class Logger : ILogger
    {
        private static Logger logger;

        #region ILogger Members

        public void Error(string message)
        {
            InvokeLogged(message, LogLevel.Error);
        }

        public void Warn(string message)
        {
            InvokeLogged(message, LogLevel.Warn);
        }

        public void Info(string message)
        {
            InvokeLogged(message, LogLevel.Info);
        }

        public event LogPresent Logged;

        #endregion

        public static ILogger GetLogger()
        {
            return logger ?? (logger = new Logger());
        }

        private void InvokeLogged(string message, LogLevel level)
        {
            LogPresent handler = Logged;
            if (handler != null) handler(new Log(message, level));
        }
    }
}